{% extends "base.html" %}
{% block content %}

    {% if session.user_info.is_admin %}
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title" style="height:42px;">
                    项目更新
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <p id="insp_update"></p>
                        <button type="button" style="margin-left: 3px;float:right;" class="btn btn-primary" onclick="update()">更新</button>
                        <button type="button" style="margin-left: 3px;float:right;" class="btn btn-white" onclick="insp_update()">检查</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% endif %}
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title" style="height:42px;">
                    更新历史
                </div>
                <div class="ibox-content">
                    <div id="vertical-timeline" class="vertical-container dark-timeline center-orientation">

                        <div class="vertical-timeline-block">
                            <div class="vertical-timeline-icon blue-bg">
                                <i class="fa fa-file-text"></i>
                            </div>

                            <div class="vertical-timeline-content">
                                <h2>Crysadm+ 更新日记 v1.6</h2>
                                <p>温馨提示：以后更新历史在GitHub代码仓库上查看</p>
                                <p><a href="https://github.com/hauntek/crysadm/blob/master/README.md"> 查看更新历史</a></p>
                                <a href="https://github.com/hauntek/crysadm" class="btn btn-sm btn-success"> 下载源代码</a>
                                <span class="vertical-date">
                                    <small>4月26日</small>
                                </span>
                            </div>
                        </div>

                        <div class="vertical-timeline-block">
                            <div class="vertical-timeline-icon blue-bg">
                                <i class="fa fa-file-text"></i>
                            </div>

                            <div class="vertical-timeline-content">
                                <h2>Crysadm+ 更新日记 v1.4</h2>
                                <p>更新及改动的太多地方了，大家自己下载源代码后查看吧</p>
                                <a href="https://github.com/hauntek/crysadm" class="btn btn-sm btn-success"> 下载源代码</a>
                                <span class="vertical-date">
                                    <small>4月14日</small>
                                </span>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block js_logic %}
    {% if session.user_info.is_admin %}
    <script>
        (function () {
            insp_update();
        })();

        //检查
        function insp_update() {
            document.getElementById("insp_update").innerHTML = '';
            $.ajax({
                type: "POST",
                url: "/admin/insp_update",
                dataType: "json",
                success: function (data) {
                    if (data.r == 'ok') {
                        if (data.list.length == 0) {
                            document.getElementById("insp_update").innerHTML="本地源代码和云端一致，无需更新";
                        } else {
                            for (var i = 0;i < data.list.length; i++) {
                                var file = '发现更新的文件：' + data.list[i].file + "<br/>";
                                document.getElementById("insp_update").innerHTML+=file;
                            }
                            document.getElementById("insp_update").innerHTML+="<br/>" + "总共：" + data.list.length + "文件";
                        }
                    } else {
                        document.getElementById("insp_update").innerHTML=data.msg;
                    }
                }
            });
        };

        //更新
        function update() {
            document.getElementById("insp_update").innerHTML = '';
            $.ajax({
                type: "POST",
                url: "/admin/update",
                dataType: "json",
                success: function (data) {
                    if (data.r == 'ok') {
                        //实时反馈百分比进度
                        var timer = setInterval(function(){
                            $.ajax({
                                type: "POST",
                                url: "/admin/update/progress",
                                dataType: "json",
                                success: function (data) {
                                    if (data.result == 100 || data.result == 72) {
                                        document.getElementById("insp_update").innerHTML="恭喜你，项目更新完成.";
                                        clearInterval(timer);
                                    } else {
                                        document.getElementById("insp_update").innerHTML="正在更新中 " + data.result + "%";
                                    }
                                }
                            });
                        },1000);
                    } else {
                        document.getElementById("insp_update").innerHTML=data.msg;
                    }
                }
            });
        };
    </script>
    {% endif %}
{% endblock %}

{% block navibar %}
    <div class="col-sm-4">
        <h2>关于</h2>
        <ol class="breadcrumb">
            <li>
                <a href="/">Home</a>
            </li>
            <li class="active">
                <strong>About</strong>
            </li>
        </ol>
    </div>
{% endblock %}
{% set active_page = "about" %}
